const { packageManager, log } = require("../utils");
const configLang = require("../configLang");
const t = require("../../config/dict");

module.exports = (source, options) => {
  configLang({ lang: "english" }, (context) => {
    const pm = packageManager();
    pm.register(source)
      .then(
        () => (
          log("success", {
            message: [t(context.lang, "成功"), t(context.lang, "。")].join(" "),
          }),
          pm.register().catch((err) =>
            log("error", {
              message: [t(context.lang, "失败"), err].join(" "),
            })
          )
        )
      )
      .catch((err) =>
        log("error", { message: [t(context.lang, "失败"), err].join(" ") })
      );
  });
};
